package lsp

import (
	"errors"
	"gitee.com/big_meteor/lsp/utils"
	"strings"
)

type anySchema struct {
	label   string
	message map[string]string
}

func (schema anySchema) error(method string, args map[string]interface{}) error {
	msg, has := schema.message[method]
	if false == has {
		return errors.New("Error code \"" + method + "\" is not defined, your custom type is missing the correct messages definition")
	}

	if nil == args {
		args = make(map[string]interface{})
	}

	args["label"] = "\"" + schema.label + "\""
	for key, value := range args {
		msg = strings.Replace(msg, "{{#"+key+"}}", utils.Strval(value), 1)
	}
	return errors.New(msg)
}
